package On_class.L0422;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

//runnable
public class TicketRunnable implements Runnable{
    int ticket =100;
    @Override
    public void run() {

        while (ticket>0){
            Lock lock=new ReentrantLock();

            try {
                Thread.sleep(500);
            }catch (Exception e){
                e.printStackTrace();
            }
            lock.lock();
            String name=Thread.currentThread().getName();
            System.out.println(name+"正在出售第"+(ticket--)+"张票");
            lock.unlock();
        }

    }

}
